package com.zznzzn.androidshixun0826;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class ContactDBHelper extends SQLiteOpenHelper {

    public static final String DB_NAME = "mycontactlib.db";
    public static final String TABLE_NAME = "contacts";
    public static final int DB_VERSION = 1;
    private static ContactDBHelper helper;


    public ContactDBHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String createtable = String.format("create table if not exists %s(id INTEGER PRIMARY KEY autoincrement , name text,phone text,address text,photo blob)", TABLE_NAME);
        db.execSQL(createtable);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

    public static ContactDBHelper getInstance(Context context) {
        if (helper == null) {
            helper = new ContactDBHelper(context);
        }
        return helper;
    }
}
